home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Megarom
/
Megarom Macintosh CD Software (Quantum Leap)(1992).iso
/
CDEV⁄RDEV
/
INITShare ƒ
/
INIT32.a
< prev
next >
Wrap
Text File
|
1988-06-24
|
7KB
|
280 lines
; INIT to include a specified folder in the Poor Man's Search Path
; The Name of the folder is in STR 128
INCLUDE 'Traps.a'
INCLUDE 'ToolEqu.a'
INCLUDE 'SysEqu.a'
INCLUDE 'SysErr.a'
;Install the patches to _Open, _OpenRF and _GetFileInfo
Main
init32
MOVE.L A0,-(SP) ;Get the Handle to ourself
_DetachResource ;Detach ourself , so we survive
LINK A6,#-ioHVQElSize ;Allocate a ParamBlock Record
CLR.L -(SP)
MOVE.W #-4048,-(SP)
_GetString ;Get Handle to Folder Name string
MOVE.L (SP),A0
_HLock ;Lock it
MOVE.L (A0),A1 ;Get Pointer to Folder Name string
LEA -ioHVQElSize(A6),A0 ;Point to Params
CLR.L ioCompletion(A0)
MOVE.L A1,ioFileName(A0) ;Point to Folder Name string
CLR.W ioVRefNum(A0)
MOVE.L #'JGS0',ioWDProcID(A0)
CLR.L ioWDDirID(A0)
_OpenWD ;Open our Folder as a Working Directory
BEQ.S OK
MOVE.L (SP)+,A0 ;Folder not found, Clean up string
_HUnlock
BRA.S EndInstall ;and return without patching
OK
LEA WDRefNum,A1
MOVE.W ioVRefNum(A0),(A1) ;Save Working Directory Refnum
MOVE.L (SP)+,A0
_HUnlock ;Unlock the Folder Name string
LEA -ioHVQElSize(A6),A0 ;Point to Params
CLR.L ioCompletion(A0)
CLR.L ioFileName(A0) ;Clear name pointer
CLR.W ioVRefNum(A0)
CLR.W ioVolIndex(A0)
_HGetVInfo ;Get volume info
BNE.S EndInstall
LEA BlVRefNum,A1
MOVE.W ioVRefNum(A0),(A1) ;Save VRefNum of blessed folder
LEA BlDirID,A1
MOVE.L ioVFndrInfo(A0),(A1) ;Save dirID of blessed folder
MOVE.W #$00,D0 ;Get old _Open address
_GetTrapAddress
LEA OldOpenAdr,A1
MOVE.L A0,(A1) ;Save it for use in the patches
LEA NewOpen,A0 ;Point to new _Open
MOVE.W #$00,D0 ;Patch the _OpenRF trap
_SetTrapAddress
MOVE.W #$0A,D0 ;Get old _OpenRF address
_GetTrapAddress
LEA OldOpenRFAdr,A1
MOVE.L A0,(A1) ;Save it for use in the patches
LEA NewOpenRF,A0 ;Point to new _OpenRF
MOVE.W #$0A,D0 ;Patch the _OpenRF trap
_SetTrapAddress
MOVE.W #$0C,D0 ;Get old _GetFileInfo address
_GetTrapAddress
LEA OldGetFIAdr,A1
MOVE.L A0,(A1) ;Save it for use in the patches
LEA NewGetFI,A0 ;Point to new _GetFileInfo
MOVE.W #$0C,D0
_SetTrapAddress ;Patch the _GetFileInfo trap
EndInstall
UNLK A6 ;Clean up stack
RTS
;The New _Open trap
NewOpen
MOVEM.L A0-A6/D1-D7,-(SP) ;Save all regs. except D0
LEA OldOpenAdr,A2 ;Get the old trap
MOVE.L (A2),A2
JSR (A2) ;Do old trap
MOVEM.L (SP)+,A0-A6/D1-D7 ;Restore regs.
CMP.W #fnfErr,D0 ;File Not Found Error in old WD?
BNE.S NoOpenErr ;No, just return
MOVE.W ioVRefNum(A0),-(SP) ;Save old RefNum
MOVE.W D0,-(SP) ;Save old Error
MOVEM.L A0-A6/D1-D7,-(SP) ;Save regs.
MOVE.W WDRefNum,ioVRefNum(A0) ;Try our WD
LEA OldOpenAdr,A2 ;Get the old trap
MOVE.L (A2),A2
JSR (A2) ;Do old trap in our Folder
MOVEM.L (SP)+,A0-A6/D1-D7 ;Restore regs.
TST.W D0 ;Error in new WD?
BEQ.S @1 ;No, Clean up and return
MOVE.W (SP),D0 ;Restore old Error
MOVE.W 2(SP),ioVRefNum(A0) ;Restore old VRefNum
@1 ADDQ #4,SP ;Clean Stack
NoOpenErr
RTS
;The New _OpenRF trap
NewOpenRF
MOVEM.L A0-A6/D1-D7,-(SP) ;Save all regs. except D0
LEA OldOpenRFAdr,A2 ;Get the old trap
MOVE.L (A2),A2
JSR (A2) ;Do old trap
MOVEM.L (SP)+,A0-A6/D1-D7 ;Restore regs.
CMP.W #fnfErr,D0 ;File Not Found Error in old WD?
BNE.S NoORFErr ;No, just return
MOVE.W ioVRefNum(A0),-(SP) ;Save old RefNum
MOVE.W D0,-(SP) ;Save old Error
MOVEM.L A0-A6/D1-D7,-(SP) ;Save regs.
MOVE.W WDRefNum,ioVRefNum(A0) ;Try our WD
LEA OldOpenRFAdr,A2 ;Get the old trap
MOVE.L (A2),A2
JSR (A2) ;Do old trap in our Folder
MOVEM.L (SP)+,A0-A6/D1-D7 ;Restore regs.
TST.W D0 ;Error in new WD?
BEQ.S @1 ;No, Clean up and return
MOVE.W (SP),D0 ;Restore old Error
MOVE.W 2(SP),ioVRefNum(A0) ;Restore old VRefNum
@1 ADDQ #4,SP ;Clean Stack
NoORFErr
RTS
;Patch to the _GetFileInfo trap
NewGetFI
LEA Recursive,A1
ADD.W #1,(A1)
MOVEM.L A0-A6/D1-D7,-(SP) ;Save all regs. except D0
LEA OldGetFIAdr,A2 ;Get the old trap
MOVE.L (A2),A2
JSR (A2) ;Do old trap
MOVEM.L (SP)+,A0-A6/D1-D7 ;Restore original regs.
CMP.W #fnfErr,D0 ;File Not Found Error?
BNE.S NoGFIErr ;No, just return
TST.W ioFDirIndex(A0) ;Is this an indexed GetFileInfo?
BLE.S NoGFIErr ;No, just return
LEA Recursive,A1
CMP.W #1,(A1) ;Recursive call?
BGT.S NoGFIErr ;Yes, just return
JSR CheckBlFolder ;Are we looking at the blessed folder?
BNE.S NoGFIErr ;No, just return
MOVE.W ioVRefNum(A0),-(SP) ;Save old RefNum
MOVE.W D0,-(SP) ;Save old Error
MOVE.W ioFDirIndex(A0),-(SP) ;Save the wanted FileIndex
;Find out how many files in old WD, to adjust FileIndex
CLR.W ioFDirIndex(A0) ;Initialize FileIndex
nextFile
ADD.W #$1,ioFDirIndex(A0) ;Next FileIndex
MOVEM.L A0-A6/D1-D7,-(SP) ;Save regs.
LEA OldGetFIAdr,A2 ;Get the old trap
MOVE.L (A2),A2
JSR (A2) ;Do old trap
MOVEM.L (SP)+,A0-A6/D1-D7 ;Restore regs.
TST.W D0 ;FileIndex too large (File not found)?
BEQ.S nextFile ;Not yet, try next index
CMP.W #fnfErr,D0 ;File Not Found Error in old WD?
BNE.S OldError ;No, Some other error, just return
MOVE.W (SP),D0 ;Get wanted FileIndex
SUB.W ioFDirIndex(A0),D0 ;Adjust wanted FileIndex to our WD
ADD.W #1,D0
MOVE.W D0,ioFDirIndex(A0) ;Set FileIndex in Param Block
MOVE.W WDRefNum,ioVRefNum(A0) ;Point to our WD
MOVEM.L A0-A6/D1-D7,-(SP) ;Save regs.
LEA OldGetFIAdr,A2 ;Get the old trap
MOVE.L (A2),A2
JSR (A2) ;Do old trap
MOVEM.L (SP)+,A0-A6/D1-D7 ;Restore regs.
TST.W D0 ;Error in new WD?
BEQ.S Cleanup ;No, Clean up and return
OldError
MOVE.W (SP),ioFDirIndex(A0) ;Restore old Index
MOVE.W 2(SP),D0 ;Restore old Error
MOVE.W 4(SP),ioVRefNum(A0) ;Restore old VRefNum
Cleanup
ADDQ #6,SP ;Clean Stack
NOGFIErr
LEA Recursive,A1
SUB.W #1,(A1) ;Clear Recursive flag
RTS
;Subroutine to check if ioVRefNum(A0) is pointing to the blessed folder
CheckBlFolder
MOVEM.L A0-A6/D0-D7,-(SP) ;Save regs.
LINK A6,#-ioHFQElSiz ;Allocate a ParamBlock Record
MOVE.L A0,A1
LEA -ioHFQElSiz(A6),A0 ;Point to Params
CLR.L ioCompletion(A0)
CLR.L ioFileName(A0) ;Clear name pointer
TST.W ioVRefNum(A1) ;Default Directory?
BEQ.S @2 ;Yes, get Default Directory info
MOVE.W ioVRefNum(A1),ioVRefNum(A0)
CLR.W ioWDIndex(A0)
CLR.L ioWDProcID(A0)
CLR.W ioWDVRefNum(A0)
_GetWDInfo ;Get Working Directory info
BRA.S @3
@2 _HGetVol ;Get Default Directory info
@3 BNE.S @1
MOVE.L BlDirID,D0
CMP.L ioWDDirID(A0),D0 ;Is it the DirID of the blessed folder?
BNE.S @1 ;No, return
MOVE.W BlVRefNum,D0
CMP.W ioWDVRefNum(A0),D0 ;Is it the VRefNum of blessed folder?
@1
UNLK A6 ;Clean up stack
MOVEM.L (SP)+,A0-A6/D0-D7 ;Restore regs.
RTS
OldOpenAdr
DC.L 0 ;Saved old _Open address
OldOpenRFAdr
DC.L 0 ;Saved old _OpenRF address
OldGetFIAdr
DC.L 0 ;Saved old _GetFileInfo address
WDRefNum
DC.W 0 ;The WDRefNum of our Folder
BlVRefNum
DC.W 0 ;Volume reference number of blessed folder
BlDirID
DC.L 0 ;Directory ID of blessed folder
Recursive
DC.W 0 ;Recursion flag
END